/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package persistence;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * This class is a JPA entity and is used to represent a ticket
 * as it will be stored in the database
 * 
 * @author Amigos do Noddy
 *
 */
@Entity
@Table(name = "TICKET", schema = "APP")
@NamedQueries({@NamedQuery(name = "Ticket.findByIdticket", query = "SELECT t FROM Ticket t WHERE t.idticket = :idticket"), @NamedQuery(name = "Ticket.findByTitle", query = "SELECT t FROM Ticket t WHERE t.title = :title"), @NamedQuery(name = "Ticket.findByDate", query = "SELECT t FROM Ticket t WHERE t.date = :date"), @NamedQuery(name = "Ticket.findByStatus", query = "SELECT t FROM Ticket t WHERE t.status = :status"), @NamedQuery(name = "Ticket.findByActive", query = "SELECT t FROM Ticket t WHERE t.active = :active")})
public class Ticket implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "IDTICKET", nullable = false)
    private Integer idticket;
    @Lob
    @Column(name = "TICKET", nullable = false)
    private String ticket;
    @Column(name = "TITLE", nullable = false)
    private String title;
    @Column(name = "DATE", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date date;
    @Column(name = "STATUS", nullable = false)
    private short status;
    @Column(name = "ACTIVE", nullable = false)
    private short active;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "ticket")
    private Collection<Assignment> assignmentCollection;
    @JoinColumn(name = "REFIDPERSON_UTILIZADOR", referencedColumnName = "REFIDPERSON")
    @ManyToOne
    private Utilizador refidpersonUtilizador;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "refidticket")
    private Collection<Comment> commentCollection;

    /**
     * Default constructor
     */
    public Ticket() {
    }

    /**
     * Class constructor
     * @param idticket ticket id
     */
    public Ticket(Integer idticket) {
        this.idticket = idticket;
    }

    public Ticket(Integer idticket, String ticket, String title, Date date, short status, short active) {
        this.idticket = idticket;
        this.ticket = ticket;
        this.title = title;
        this.date = date;
        this.status = status;
        this.active = active;
    }

    /**
     * Gets the id of the ticket
     * @return ticket id
     */
    public Integer getIdticket() {
        return idticket;
    }

    /**
     * Sets the id of the ticket
     * @param idticket ticket id
     */
    public void setIdticket(Integer idticket) {
        this.idticket = idticket;
    }

    /**
     * Gets the ticket text
     * @return ticket text
     */
    public String getTicket() {
        return ticket;
    }

    /**
     * Sets the ticket text
     * @param ticket text
     */
    public void setTicket(String ticket) {
        this.ticket = ticket;
    }

    /**
     * Gets the ticket title
     * @return ticket title
     */
    public String getTitle() {
        return title;
    }

    /**
     * Sets the ticket title
     * @param title ticket title
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * Gets the date of the ticket
     * @return date of the ticket
     */
    public Date getDate() {
        return date;
    }

    /**
     * Sets the date of the ticket
     * @param date date of the ticket
     */
    public void setDate(Date date) {
        this.date = date;
    }

    /**
     * Gets the status of the ticket
     * @return status of the ticket
     */
    public short getStatus() {
        return status;
    }

    /**
     * Sets the status of the ticket
     * 
     * @param status status of the ticket
     */
    public void setStatus(short status) {
        this.status = status;
    }

    /**
     * Gets the active state of the ticket
     * @return active state
     */
    public short getActive() {
        return active;
    }

    /**
     * Sets the active state of the ticket
     * @param active active state
     */
    public void setActive(short active) {
        this.active = active;
    }

    /**
     * Gets the list of assignments
     * @return list of assignments
     */
    public Collection<Assignment> getAssignmentCollection() {
        return assignmentCollection;
    }

    /**
     * Sets the list of assignments
     * @param assignmentCollection list of assignments
     */
    public void setAssignmentCollection(Collection<Assignment> assignmentCollection) {
        this.assignmentCollection = assignmentCollection;
    }

    /**
     * Gets the id of the user
     * @return user id
     */
    public Utilizador getRefidpersonUtilizador() {
        return refidpersonUtilizador;
    }

    /**
     * Sets the id of the user
     * @param refidpersonUtilizador user id
     */
    public void setRefidpersonUtilizador(Utilizador refidpersonUtilizador) {
        this.refidpersonUtilizador = refidpersonUtilizador;
    }

    /**
     * Gets the list of comments
     * @return list of comments
     */
    public Collection<Comment> getCommentCollection() {
        return commentCollection;
    }

    /**
     * Sets the list of comments
     * @param commentCollection list of comments
     */
    public void setCommentCollection(Collection<Comment> commentCollection) {
        this.commentCollection = commentCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idticket != null ? idticket.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Ticket)) {
            return false;
        }
        Ticket other = (Ticket) object;
        if ((this.idticket == null && other.idticket != null) || (this.idticket != null && !this.idticket.equals(other.idticket))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "persistence.Ticket[idticket=" + idticket + "]";
    }

}
